//
//  CancelAndTransferModel.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/20.
//

#import "CancelAndTransferModel.h"
@interface CancelAndTransferModel ()

@end
@implementation CancelAndTransferModel

- (NSMutableArray<PondUserModel *> *)tempUserModel{
    if(!_tempUserModel){
        _tempUserModel = [NSMutableArray array];
    }
    return _tempUserModel;
}
- (CGFloat)TransferCellH{
   
    CGFloat imgH = kwt(135);
    if(self.tempUserModel.count > 3){
        imgH = kwt(225);
    }
  
    return kwt(63 + 5) + imgH;
}
- (CGFloat)CancelCellH{
    if(self.issueCode == 1){///系统下发
        return kwt(63);
    }
    if(self.cancelRangeCode == 1){
        return kwt(63 * 3);
    }
    return kwt(63 * 2);
}
- (void)setVoiceUrl:(NSString *)voiceUrl{
    _voiceUrl = voiceUrl;
    NSError * error ;
    AVURLAsset* audioAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:voiceUrl] options: @{AVURLAssetPreferPreciseDurationAndTimingKey:@(YES)}];
    [audioAsset loadValuesAsynchronouslyForKeys:@[@"duration"] completionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            AVKeyValueStatus status = [audioAsset statusOfValueForKey:@"duration" error:nil];
            if(status == AVKeyValueStatusLoaded){
                CMTime audioDuration = audioAsset.duration;
                float audioDurationSeconds = CMTimeGetSeconds(audioDuration);
                self.voiceDuration = [NSString stringWithFormat:@"%.0f\"",round(audioDurationSeconds)];
                if(self.openDurationBlock){
                    self.openDurationBlock(self.voiceDuration);
                }
            }
        });
    }];
    
}
///取消任务提示
- (NSString *)QXRWHudString{
    if(self.applyReasonCode == 0){
        return @"请选择取消原因";
    }
    if(self.issueCode != 1){
        if(self.cancelRange == 0){
            return @"请选择取消范围";
        } else {
            if(self.cancelStartTime.length < 0 || self.cancelEndTime.length < 0){
                return @"请选择取消时间";
            }
        }
    }
   
    return @"";
}


///取消任务
- (NSMutableDictionary *)QXRWDict{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setObject:self.ID forKey:@"id"];
    [dict setObject:self.TJvoiceUrl forKey:@"voiceUrl"];
    [dict setObject:self.applyReason forKey:@"applyReason"];
    [dict setObject:@(self.applyReasonCode) forKey:@"applyReasonCode"];
    if(self.issueCode != 1){
        [dict setObject:self.cancelRange forKey:@"cancelRange"];
        [dict setObject:@(self.cancelRangeCode) forKey:@"cancelRangeCode"];
        if(self.cancelRangeCode == 1){
            [dict setObject:self.cancelStartTime forKey:@"cancelStartTime"];
            [dict setObject:self.cancelEndTime forKey:@"cancelEndTime"];
        }
    }

    
    
    return dict;
}

///转交任务提示
- (NSString *)ZJRWHudString{
    if(self.tempUserModel.count < 1){
        return @"请选择转交人";
    }
    
    if(self.applyReasonCode == 0){
        return @"请选择转交原因";
    }
    
    return @"";
}
///转交任务
- (NSMutableDictionary *)ZJRWDict{
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setObject:self.ID forKey:@"id"];
    [dict setObject:self.TJvoiceUrl forKey:@"voiceUrl"];
    [dict setObject:self.applyReason forKey:@"applyReason"];
    [dict setObject:@(self.applyReasonCode) forKey:@"applyReasonCode"];
    NSMutableArray * tempUserModel = [NSMutableArray array];
    for (PondUserModel * model in self.tempUserModel) {
//        [tempUserModel addObject:@{
//            @"realName":model.realName,
//            @"userId":model.userId,
//        }];
        [dict setObject:@{
            @"realName":model.realName,
            @"userId":model.userId,
        } forKey:@"tempUserModel"];

    }
//    [dict setObject:tempUserModel forKey:@"tempUserModel"];

    return dict;
}
@end

@implementation getDictTextModel

@end
